<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>uni-app-web-view</title>
    <style type="text/css">
		.wrapper{
			text-align: center;
			padding-top: 80px;
		}
		.btn {
			display: block;
			margin: 20px auto;
			padding: 5px;
			background-color: #007aff;
			border: 0;
			color: #ffffff;
			height: 40px;
			width: 200px;
		  }
		[v-clock]{
			display: none;
		 }
    </style>
  </head>
  <body>
    
	<div id="app" class="wrapper" v-clock>
		<img :src="payStatus==='success'?'passed.png':'not-pass.png'"/>
		<p>{{msg}}</p>
		<button type="button" class="btn">确定</button>
	</div>
    <!-- 微信 JS-SDK 如果不需要兼容小程序，则无需引用此 JS 文件 -->
    <!-- <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script> -->
    <!-- uni 的 SDK -->
	
	<!-- <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js"></script>  -->
	<script type="text/javascript" src="./vue.global.js"></script>
	<script type="text/javascript" src="./jweixin-1.4.0.js"></script>
	<script type="text/javascript" src="./uni.webview.1.5.1.js"></script>
	
    <script type="text/javascript">
		const { createApp, ref } = Vue
		
		  createApp({
		    setup() {
		      var arr = window.location.search
		      // var queryStr = location.search.split("?")[1];
		      var strs = arr.split("?")[1];
			  if(!strs) return
		      var paramt = strs.split("&");
		      var obj={};
		      for(let i=0;i<paramt.length;i++){
		          let g  = paramt[i].split("=");
		          obj[g[0]]=g[1];
		      }
			  const msg = ref('支付成功')
			  const payStatus = ref(obj.pay_status)
			  if(payStatus.value==='fail'){
				  fetch('/api/front/pay_error_info', {
				    method:'POST',// or 'PUT'
				    body: new URLSearchParams({
				  	  pay_type: obj.pay_type,
				  	  trade_no: obj.trade_no
				    }),// data can be `string` or {object}!
				    headers:new Headers({
				      'Content-Type':'application/x-www-form-urlencoded'
				    })
				  }).then(res => res.json())
				  .catch(error => console.error('Error:', error))
				  .then(response => {
					  if(response.code===200){
						  msg.value = response.data
					  }
					
				  	console.log('Success:', response)
				  });
			  }
			  
			  
			  document.addEventListener('UniAppJSBridgeReady', function() {
			    document.querySelector('.btn').addEventListener('click', function(evt) {
			      // uni.navigateTo({
			      //     url: '/pages/order_pay_status/index'  
			      // });
				  const orderStatus = payStatus.value==='success'?1:0
				  console.log('orderStatus',orderStatus)
				  uni.redirectTo({
				  	url:`/pages/users/order_list/index?orderStatus=${orderStatus}`
				  })
			    });
			  });
		      return {
		        payStatus,
				msg
		      }
		    }
		  }).mount('#app')
		
		
     
    </script>
  </body>
</html>
